<?php

namespace app\common\model;

use think\Model;
use app\common\model\Base;
use traits\model\SoftDelete;

class Order extends Base {

    use SoftDelete;

    protected $deleteTime = 'delete_time';

    public function getStatusTextAttr($value, $data) {

        if ($data['status'] < 20)
            return '<span style="color:red">' . config_value('order_status', $data['status']) . '</span>';
        else
            return config_value('order_status', $data['status']);
    }

    public function getExpressNameAttr($value, $data) {
        return db('express')->where('id', $data['express_id'])->value('title');
    }

    public function getNicknameAttr($value, $data) {
        return db('member')->cache(true)->where('id', $data['member_id'])->value('nickname');
    }

    public function model_where($wheres = []) {


        foreach ($wheres as $key => $value) {
            $this->where($key, $value[0], $value[1]);
        }


        if (request()->get('keyword'))
            $this->where('order_number', 'like', '%' . request()->get('keyword') . '%');



        return $this;
    }

}
